<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import systemUserContractList from '@/api/system/systemUserContractList'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  systemUserContractList.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  systemUserContractList.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_system_user_contract_list',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: systemUserContractList.getList,
  recycleApi: systemUserContractList.getRecycleList,
  add: {
    show: true,
    api: systemUserContractList.save,
    auth: ['system:userContractList:save']
  },
  edit: {
    show: true,
    api: systemUserContractList.update,
    auth: ['system:userContractList:update']
  },
  delete: {
    show: true,
    api: systemUserContractList.deletes,
    auth: ['system:userContractList:delete'],
    realApi: systemUserContractList.realDeletes,
    realAuth: ['system:userContractList:realDeletes']
  },
  recovery: {
    show: true,
    api: systemUserContractList.recoverys,
    auth: ['system:userContractList:recovery']
  },
  import: {
    show: true,
    url: 'system/userContractList/import',
    templateUrl: 'system/userContractList/downloadTemplate',
    auth: ['system:userContractList:import']
  },
  export: {
    show: true,
    url: 'system/userContractList/export',
    auth: ['system:userContractList:export']
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "客戶",
    dataIndex: "dept_id",
    formType: "select",
    search: true,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: "system/dept/remote",
      // 指定组件接收的props
      props: { label: "name", value: "id" },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "name"],
        // 设置数据过滤
        filter: {
          type: ["=", 2],
          status: ['=',1]
        },
        // 关联模型
        relations: [],
        
      },
      translation: true
    },
  },
  {
    title: "合同",
    dataIndex: "contract_id",
    formType: "select",
    search: true,
    dict:{
      url:'system/userContract/index',
      params:{
        page:1,
        pageSize:10000,
      },
      props:{ label: "name", value: "id" },
      remoteOption:{
        select: ["id", "name"],
      },
      translation: true
    },
    
  },
  
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'system:userContractList' } </script>